<?php
/**
* @desc 旅客表单处理
* @author kevin.wang
* @date 2015-01-01 12:00:00
**/
class PassengerForm extends BaseForm
{
	public $passenger_name;
	public $passenger_first;
	public $passenger_second;
	public $sex;
	public $certification_type;
	public $birthday;
	public $cartification_date;
	public $certification_number;
	public $mobile;
	private $_form_data;
	//表单规则
	public function rules()
	{
		return array(
			array('passenger_name, passenger_first, passenger_second', 'required', 'message'=>'旅客姓名不能为空'),
			array('sex, certification_type', 'boolean', 'message'=>'性别和证件类型输入有误'),
			array('birthday, cartification_date', 'required', 'message'=>'日期输入有误'),
			array('certification_number, mobile', 'required', 'message'=>'证件或手机输入有误')
		);
	}
	//数据校验
	public function validateForm(array $form){
		if(empty($form)){
			$this->addError('error','旅客信息不能为空');
			return false;
		}
		foreach($form as $value){
			$this->attributes = $value;
			if(!$this->validate()){
				return false;
			}
		}
		$this->_form_data = $form;
		return true;
	}
	//返回写入订单需要的数据
	public function getPassengerData($orderSn){
		$return = array();
		if(empty($this->_form_data)){
			return $return;
		}
		$userInfo = json_decode(Yii::app()->session['userinfo'], true);
		foreach($this->_form_data as $key=>$value){
			$value['user_id'] = $userInfo['user_id'];
			$value['order_sn'] = $orderSn;
			$return[] = $value;
		}
		return $return;
	}
}
